<?php

/**
 * Ventas form.
 *
 * @package    tercermilenio
 * @subpackage form
 * @author     Your name here
 */
class VentasForm extends BaseVentasForm {

    public function configure() {

        $PagosForm = new FormaPagoForm;
        $this->mergeForm($PagosForm);

        $this->widgetSchema['tarjeta_cuotas']->setAttribute('maxlength', '2');
        $this->widgetSchema['tarjeta_cuotas']->setAttribute('size','4'); //Setea a traves de CSS
        $this->widgetSchema['tarjeta_importe']->setAttribute('size','9'); //Setea a traves de CSS

                $this->widgetSchema['vta_cliente'] = new sfWidgetFormChoice(array('choices' => array(), 'label' => 'Cliente'));
        $this->widgetSchema['vta_cliente']->setOption('renderer_class', 'sfWidgetFormJQueryAutocompleter');
        $this->widgetSchema['vta_cliente']->setOption('renderer_options', array(
            'url' => sfContext::getInstance()->getController()->genUrl('ventas/autocompletarCliente'),
        ));
    }

    public function setup() {

        parent::setup();
        
        $tiposVenta = array(
            '1' => 'Definitiva',
            '2' => 'Condicional',
        );


        $this->setWidgets(array(
            'vta_id' => new sfWidgetFormInputHidden(),
            //'vta_nro_factura' => new sfWidgetFormInput(array('label' => 'Nº Factura')),
            //'vta_cliente' => new sfWidgetFormPropelChoice(array('model' => 'Clientes', 'add_empty' => 'Seleccione un cliente', 'label' => 'Cliente')),
            //'vta_fecha' => new sfWidgetFormDate(array('label' => 'Fecha')),
            //'vta_tipo' => new sfWidgetFormPropelChoice(array('model' => 'TipoVentas', 'add_empty' => 'Seleccione un tipo de venta', 'label' => 'Tipo')),
            'vta_tipo' => new sfWidgetFormPropelChoice(array('model' => 'TipoVentas','choices' => array($tiposVenta), 'label' => 'Tipo','expanded'=>true,'multiple'=> false)),
                //'vta_total'           => new sfWidgetFormInput(),
                //'vta_usuario'         => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => 'Seleccione un usuario')),
                //'devoluciones_list'   => new sfWidgetFormPropelChoiceMany(array('model' => 'Productos')),
                //'detalle_ventas_list' => new sfWidgetFormPropelChoiceMany(array('model' => 'Productos')),
        ));

        $this->widgetSchema['vta_cliente'] = new sfWidgetFormChoice(array('choices' => array(), 'label' => 'Cliente'));
        $this->widgetSchema['vta_cliente']->setOption('renderer_class', 'sfWidgetFormJQueryAutocompleter');
        $this->widgetSchema['vta_cliente']->setOption('renderer_options', array(
            'url' => sfContext::getInstance()->getController()->genUrl('ventas/autocompletarCliente'),
        ));

        $this->setValidators(array(
            'vta_id' => new sfValidatorPropelChoice(array('model' => 'Ventas', 'column' => 'vta_id', 'required' => false)),
            //'vta_nro_factura' => new sfValidatorInteger(),
            'vta_cliente' => new sfValidatorPropelChoice(array('model' => 'Clientes', 'column' => 'cli_id')),
            //'vta_fecha' => new sfValidatorDate(),
            'vta_tipo' => new sfValidatorPropelChoice(array('model' => 'TipoVentas', 'column' => 'tip_vta_id')),
                //'vta_total'           => new sfValidatorNumber(),
                //'vta_usuario'         => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'column' => 'id')),
                //'devoluciones_list'   => new sfValidatorPropelChoiceMany(array('model' => 'Productos', 'required' => false)),
                //'detalle_ventas_list' => new sfValidatorPropelChoiceMany(array('model' => 'Productos', 'required' => false)),
        ));

        $this->widgetSchema->setNameFormat('ventas[%s]');

        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
    }

}
